<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>notes</title>
	<style type="text/css">
	  table
	  {
	  border-collapse: collapse;
	  }
	  table, tr, th, td
	  {
	  border: 1px solid black;
	  padding-left: 8px;
	  padding-right: 8px;
	  }
	  th, td
	  {
	  min-width: 2em;
	  }
	  pre
	  {
	  border-style: solid
	  }
	  .comment
	  {
	  color: green;
	  }
	</style>
	<link rel="stylesheet" title="plain" type="text/css" href="plain.css" />
	<link rel="alternate stylesheet" title="colour" type="text/css" href="colour.css"/>
</head>
<body>
	<h2>Notes</h2>
	<p>Plan for this class:<ol>
		<li>Review of the adventure game:<ul>
			<li>what was difficult?</li>
			<li>procedural programming</li>
			<li>a look at the structure</li>
			<li>draw in goto jumps (spaghetti)</li>
		</ul></li>
		<li>Structured programming<ul>
		    <li>block structure<ul>
			<li>you can use a block anywhere you can place a statement</li>
			<li>inside the block, code proceeds as usual</li>
			<li>variables declared inside a block are local to the block</li>
		    </ul></li>
		    <pre>

{
     statement1;
     statement2;
     ...
}
		    </pre>
		    <li>if else statement</li>
		    <pre>

     if (condition) statement1; 
     else statement2;
		    </pre>
		    <li>how it works:</li>
		    <pre>

     if (condition) goto first;
     goto second;
first:
     statement1;
     goto endif
second:
     statement2;
endif:
     ...
		    </pre>
		    <li>if else if ladder (chain)</li>
		    <pre>

     if (condition1) statement1; 
     else if (condition2) statement2; 
     else if (condition3) statement3; 
     else statement4;
		    </pre>
		    <li>how it works:</li>
		    <pre>

     if (condition1) goto first;
     goto secondCondition;
first:
     statement1;
     goto endif
secondCondition:
     if (condition2) goto second;
     goto thirdCondition;
second:
     statement2;
     goto endif;
thirdCondition:
     if (condition3) goto third;
     goto fourth;
third:
     statement3;
     goto endif;
fourth:
     statement4;
endif:
     ...
		    </pre>
		    <li>block structure and if together:</li>
		    <pre>

     if (condition) {

          statement1;
          statement2;
          ...
     }
		    </pre>
		    <li>how it works:</li>
		    <pre>

     if (condition) goto block;
     goto endif;
block:
     statement1;
     statement2;
     ...
endif:
     ...
		    </pre>
		    <li>if else blocks:</li>
		    <pre>

     if (condition) {

          statement1;
          statement2;
          ...
     
     } else {

          statement3;
          statement4;
          ...
     }
		    </pre>
		    <li>how it works:</li>
		    <pre>

     if (condition) goto block1;
     goto block2;
block1:
     statement1;
     statement2;
     ...
     goto endif;
block2:
     statement3;
     statement4;
     ...
endif:
     ...
		    </pre>
		    <li>switch statement</li>
		    <pre>

     switch (variable) {

     case value1:
          statement1;
          statement2;
          ...
          break;

     case value2:
          statement 3;
          break;

     default:
          statement 4;
          break;
     }
		    </pre>
		    <li>works like an if else chain</li>
		    <li>each case acts a bit like a block</li>
		    <li>don't declare variables within the block</li>

		    <li>review the adventure program</li>
		    <li>identify potential blocks and if else chains</li>
		    <li>redraw spaghetti</li>
		    <li>loops</li>
		    <li>while statement</li>
		    <pre>

     while (condition) statement;
		    </pre>
		    <li>how it works</li>
		    <pre>

loop:
     if (condition) goto body;
     goto end;
body:
     statement;
     goto loop;
end:
     ...
		    </pre>
		    <li>do while statement</li>
		    <pre>

     do statement; while (condition);
		    </pre>
		    <li>how it works</li>
		    <pre>

loop:
     statement;
     if (condition) goto loop;
     ...
		    </pre>
		    <li>redraw spaghetti</li>
		    <li>for loop</li>
		    <pre>

     for (int i = 0; i &lt; 10; ++i) {

          statement;
          x[i] = expression;
          ...
     }
		    </pre>
		    <li>scope of variables</li>
		    <li>how it works</li>
		    <pre>
     int i = 0;
loop:
     if (i &lt; 10) goto body;
     goto end;
body:
     statement;
     x[i] = expression;
     ...
     ++i;
     goto loop;
end:
     ...
		    </pre>
		</ul></li>
		<li>RPG combat<ul>
		    <li>a simple combat loop</li>
		    <li>random numbers</li>
		    <li>alternative attacks</li>
		    <li>"AI"</li>
		</ul></li>
		<li>Extend and make your own combat</li>
	  </ol>
	</p>
</body>
</html>
